//
//  ViewController.swift
//  SWIFTLEARN
//
//  Created by chichaojituan521 on 2017/5/8.
//  Copyright © 2017Y linch. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITextFieldDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = UIColor.lightGray
        let btnName:[String] = ["字符","控件1","控件2","4","5","6","7","8","9","10","11","12","13"]
        
        let btnInterval: Int = 10
        
        let btnWidth = (self.view.frame.size.width - CGFloat(btnInterval) * 5)/4.0
        
        
        for btnitem in 1...12 {
            
            let item = btnitem - 1
            
            let button = UIButton(type: .custom)
            button.tag = btnitem
            
            self.view.addSubview(button)
            
            button.setTitle(btnName[item], for: .normal)
            button.titleLabel?.font = UIFont.systemFont(ofSize: 13)
            button.backgroundColor = UIColor.orange
            
            let btncgx = btnInterval + (Int(item) % 4) * (Int(btnWidth) + btnInterval)
            let btncgy = 60 + (Int(item) / 4) * (btnInterval + 50)
            button.frame = CGRect(x:btncgx , y:btncgy , width: Int(btnWidth), height: 50)
            
            button.addTarget(self, action: #selector(buttonClickMethod(_:)),for: .touchUpInside)
        
        }
        
        
        
        
        
    }
    
    func buttonClickMethod(_ button:UIButton) {
        
        switch button.tag {
        case 1:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            
            self.present(nav1, animated: true, completion: { 
                
            })
        case 2:
            let vc2 = ViewController2()
            let nav2 = UINavigationController(rootViewController: vc2)
            vc2.view.backgroundColor = UIColor.green;
            self.present(nav2, animated: true, completion: {
                
            })
        case 3:
            let vc3 = ViewController3()
            let nav3 = UINavigationController(rootViewController: vc3)
            self.present(nav3, animated: true, completion: {
                
            })
        case 4:
            let vc4 = ViewController4()
            let nav4 = UINavigationController(rootViewController: vc4)
            self.present(nav4, animated: true, completion: {
                
            })
        case 5:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 6:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 7:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 8:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 9:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 10:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 11:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        case 12:
            let vc1 = ViewController1()
            let nav1 = UINavigationController(rootViewController: vc1)
            self.present(nav1, animated: true, completion: {
                
            })
        default:
            print("没有找到VC")
        }
        
        
        
    }
    
    
   
    
        
    
}

